﻿using ErrorCode;
using Host.Api.Application.Command;
using Host.Api.DTO;
using Host.Domain;
using Host.InfrasIntructure.Interface;
using MediatR;

namespace Host.Api.Application.Handler
{
    public class GetStationDetailQueryHandler : IRequestHandler<GetStationDetailQuery, ApiResult<StationDetailDto>>
    {
        private readonly IBaseRepository<Stations> stationRepo;
        private readonly IEFCoreDeviceRepository deviceRepo;
        private readonly IEFCoreSensorDataRepository sensorRepo;

        public GetStationDetailQueryHandler(IBaseRepository<Stations> stationRepo,IEFCoreDeviceRepository deviceRepo,IEFCoreSensorDataRepository sensorRepo)
        {
            this.stationRepo = stationRepo;
            this.deviceRepo = deviceRepo;
            this.sensorRepo = sensorRepo;
        }

        public async Task<ApiResult<StationDetailDto>> Handle(GetStationDetailQuery request, CancellationToken cancellationToken)
        {
            ApiResult<StationDetailDto> res=new ApiResult<StationDetailDto>();
            var station=await stationRepo.GetByIdAsync(request.StationId);
            if (station == null)
            {
                res.Message = "换热站Id不能为空";
                res.Code=ApiEnum.Success;
                return res;
            }
            var device=deviceRepo.GetAllByStationIdAsync(request.StationId);
            var sensor = sensorRepo.GetLatestByStationIdAsync(request.StationId);
           
        }
    }
}
